import * as Icon from "@ant-design/icons";
import React from "react";
/**
 * @desc 函数防抖
 * @param func 函数
 * @param wait 延迟执行毫秒数
 * @param immediate true 表立即执行，false 表非立即执行
 */
export function debounce(func, wait, immediate) {
  let timer = null;
  if (immediate) {
    return function () {
      if (timer) {
        clearTimeout(timer);
      }
      timer = setTimeout(() => {
        func();
      }, wait);
    };
  } else {
    return function () {
      if (timer) {
        clearTimeout(timer);
      } else {
        func();
      }
      timer = setTimeout(() => {
        timer = null;
      }, wait);
    };
  }
}

export function createIcon(name) {
  if(name){
    return React.createElement(Icon[name]);
  }
}
